/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.utn.edu.tsb.parser_xml.Interface;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author Emmanuel
 */
public class XMLFileFilter extends FileFilter{

    File file;

    @Override
    public boolean accept(File f) {
        file = f;
        if (file.isDirectory()) {
	return true;
    }
        String ext = getExtension(file);

        if (null != ext && ext.equals("xml"))
            return true;
        else
            return false;
    }

    @Override
    public String getDescription() {
        return "Archivos Xml (.xml)";
    }

    private String getExtension(File f)
    {
        String ext = null;
        String s = f.getName();
        int i = s.lastIndexOf('.');

        if (i > 0 &&  i < s.length() - 1) {
            ext = s.substring(i+1).toLowerCase();
        }
        return ext;
    }

}
